package com.ybwh.springboot2.uidgenerator;

import com.xfvape.uid.UidGenerator;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.InitializingBean;

/**
 * <p>
 *
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2023/4/17 17:46
 */
@AllArgsConstructor
public class BaiduUidGenerator implements InitializingBean {
    private static BaiduUidGenerator uidGenerator0;

    public static BaiduUidGenerator getInstance() {
        if (null == uidGenerator0) {
            throw new IllegalStateException("UidGenerator has not init !!");
        }

        return uidGenerator0;
    }


    private UidGenerator uidGenerator;


    public long genUid() {
        return uidGenerator.getUID();
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        uidGenerator0 = this;
    }
}
